﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace common
{
    public static class Utils
    {
        public static IEnumerable<ValidationResult> ShowError<T>( T t)
        {
            var type = typeof(T);
            var props=type.GetProperties();
            var rez = new List<ValidationResult>();
            foreach (var x in props)
            {
                if (x.GetType() == typeof(string))
                {
                    string val = (string)x.GetValue(t, null);
                    if (string.IsNullOrEmpty(val))
                        rez.Add(new ValidationResult(string.Format("{0} is required!",x.Name)));
                }
            }
            return rez;
        }
        //public static Func<IEnumerable<ValidationResult>, string> showerr = results =>
        //{
        //    string rez = "";
        //    foreach (ValidationResult item in results)
        //    {
        //        rez += item.ErrorMessage + Environment.NewLine;

        //    }
        //    return rez;
        //};
    }
}
